Напишите функцию sum_range(start, end), которая суммирует все целые числа от значения «start» до величины «end» включительно. Если пользователь задаст первое число большее чем второе, просто поменяйте их местами.
При решении удобно воспользоваться встроенными функциями range() и sum().
Решение:
def sum_range(start, end): if start > end: end, start = start, end return sum(range(start, end + 1))
# Тесты print(sum_range(2, 12)) print(sum_range(-4, 4)) print(sum_range(3, 2)) Результат выполнения: 77 0 5 Свой вариант решения в комментарии 💬
Напишите функцию sum_range(start, end), которая суммирует все целые числа от значения «start» до величины «end» включительно. Если пользователь задаст первое число большее чем второе, просто поменяйте их местами.
При решении удобно воспользоваться встроенными функциями range() и sum().
Решение:
def sum_range(start, end): if start > end: end, start = start, end return sum(range(start, end + 1))
# Тесты print(sum_range(2, 12)) print(sum_range(-4, 4)) print(sum_range(3, 2)) Результат выполнения: 77 0 5 Свой вариант решения в комментарии 💬
#задачи
BY Python Turbo. Уютное сообщество Python разработчиков.
The S&P 500 slumped 1.8% on Monday and Tuesday, thanks to China Evergrande, the Chinese property company that looks like it is ready to default on its more-than $300 billion in debt. Cries of the next Lehman Brothers—or maybe the next Silverado?—echoed through the canyons of Wall Street as investors prepared for the worst.
Telegram announces Search Filters
With the help of the Search Filters option, users can now filter search results by type. They can do that by using the new tabs: Media, Links, Files and others. Searches can be done based on the particular time period like by typing in the date or even “Yesterday”. If users type in the name of a person, group, channel or bot, an extra filter will be applied to the searches.
Python Turbo Уютное сообщество Python разработчиков from ms